package com.dom.domweb.modular.controller;

import com.dom.common.constants.ConstantError;
import com.dom.common.model.vo.basic.*;
import com.dom.domweb.common.RspModel;
import com.dom.domweb.dao.entity.TSysCodeTbl;
import com.dom.domweb.modular.service.BasicService;
import com.dom.domweb.modular.shiro.model.ShiroUser;
import com.dom.domweb.modular.shiro.util.ShiroUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.regex.Pattern;

/**
 * @Description 基础信息控制器
 * @Author xllei
 * @Date 2018/11/13 下午9:37
 * @Version 1.0
 **/
@RestController
@RequestMapping("/base")
public class BasicController {
    @Autowired
    private BasicService basicService;

    @RequestMapping("/getStorList")
    public RspModel getStorList() {
        ShiroUser user = ShiroUtil.getUser();

        List<StorInfo> results = basicService.getStorInfoList(user.getMemCode());
        return new RspModel(results);
    }

    @RequestMapping("/getPurcOrderStatList")
    public RspModel getPurcOrderStatList() {
        List<TSysCodeTbl> results = basicService.getPurcOrderStatList();
        return new RspModel(results);
    }

    @RequestMapping("/getVerfyStatList")
    public RspModel getVerfyStatList() {
        List<TSysCodeTbl> results = basicService.getVerfyStatList();
        return new RspModel(results);
    }

    @RequestMapping("/getSuppInfoList")
    public RspModel getSuppInfoList() {
        ShiroUser user = ShiroUtil.getUser();

        List<SuppInfo> results = basicService.getSuppInfoList(user.getMemCode());
        return new RspModel(results);
    }

    @RequestMapping("/getSuppInfo")
    public RspModel getSuppInfo(@RequestParam("suppCode") Integer suppCode){
        ShiroUser user = ShiroUtil.getUser();

        SuppInfo suppInfo = basicService.getSuppInfo(user.getMemCode(), suppCode);
        return new RspModel(suppInfo);
    }

    @RequestMapping(value = "/getPurcTypeList")
    public RspModel getPurcTypeList() {
        List<TSysCodeTbl> results = basicService.getPurcTypeList();
        return new RspModel(results);
    }

    @RequestMapping(value = "/getUserStatList")
    public RspModel getUserStatList() {
        List<TSysCodeTbl> results = basicService.getUserStatList();
        return new RspModel(results);
    }

    @RequestMapping(value = "/getOrganStatList")
    public RspModel getOrganStatList() {
        List<TSysCodeTbl> results = basicService.getOrganStatList();
        return new RspModel(results);
    }

    @RequestMapping(value = "/getRoleStatList")
    public RspModel getRoleStatList() {
        List<TSysCodeTbl> results = basicService.getRoleStatList();
        return new RspModel(results);
    }

    @RequestMapping(value = "/getOrganLevelList")
    public RspModel getOrganLevelList() {
        List<TSysCodeTbl> results = basicService.getOrganLevelList();
        return new RspModel(results);
    }

    private static Pattern NUMBER_PARTTERN = Pattern.compile("^[-\\+]?[\\d]*$");

    @RequestMapping(value = "/getSysCodeList")
    public RspModel getSysCodeListByType(@RequestParam("sysCode") String sysCode) {
//        String sysCode = "12";
        if (sysCode == null || sysCode.isEmpty()
                || !NUMBER_PARTTERN.matcher(sysCode).matches()) {
            return new RspModel(ConstantError.BLANKSYSTBLERROR);
        }
        List<TSysCodeTbl> results = basicService.getSysCodeListByType(Integer.valueOf(sysCode));
        return new RspModel(results);
    }

    @RequestMapping(value = "getMenuTypeList")
    public RspModel getMenuTypeListByType(){
        List<TSysCodeTbl> results = basicService.getMenuTypeList();
        return new RspModel(results);
    }
}
